<?php

/**
 * @package Unite Showbiz Slider for Joomla 1.7-3.1
 * @author UniteCMS.net
 * @copyright (C) 2012 Unite CMS, All Rights Reserved. 
 * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 * */
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die;

class UniteShowbizController extends JControllerUniteBaseRev {

    protected $default_view = GlobalsUniteRev::VIEW_SLIDERS;
    protected $default_layout = GlobalsUniteRev::LAYOUT_SLIDER;

    /**
     * show some image
     */
    public function showimage() {
        UniteFunctionJoomlaRev::showImageFromRequest();
        exit();
    }

    /**
     * 
     * check that captions file exists and if not - copy it to it's place.
     */
    private function checkCopyCaptionsCssFile() {

        if (file_exists(GlobalsUniteRev::$pathCaptionsCss) == false)
            copy(GlobalsUniteRev::$pathCaptionsCssOriginal, GlobalsUniteRev::$pathCaptionsCss);

        if (file_exists(GlobalsUniteRev::$pathCaptionsCss) == false)
            UniteFunctionsRev::throwError("The captions file couldn't be copied to it's place: {GlobalsUniteRev::$pathCaptionsCss}, please copy it by hand from captions-original.css from the same folder, or turn to support.");
    }

    /**
     *
     * display some view
     */
    public function display($cachable = false, $urlparams = false) {

        $isJoomla3 = UniteFunctionJoomlaRev::isJoomla3();
        $urlAssets = GlobalsUniteRev::$urlAssets;
        $document = JFactory::getDocument();
        //add custom scripts

        if ($isJoomla3){
            JHtml::_('bootstrap.framework');
		}else{
            $document->addScript($urlAssets . "jquery.min.js");
		}
//add style
        $document->addStyleSheet($urlAssets . "css/style.css");
        $document->addStyleSheet($urlAssets . "css/admin.css");

//add jquery ui
        $document->addStyleSheet($urlAssets . "jui/jquery-ui-1.8.24.custom.css");
        $document->addStyleSheet($urlAssets."css/jui/new/jquery-ui-1.10.3.custom.css?ver=3.6.1");

//add codemirror
        $document->addStyleSheet($urlAssets . "codemirror/codemirror.css");
        $document->addScript($urlAssets . "codemirror/codemirror.js");
        $document->addScript($urlAssets . "codemirror/css.js");

//add custom scripts
        $document->addScript($urlAssets . "jquery-ui-1.8.24.custom.min.js");
        $document->addScript($urlAssets . "js/admin.js?ver=3.6.1");
        $document->addScript($urlAssets . "js/jquery.tipsy.js?ver=3.6.1");
        $document->addScript($urlAssets . "js/farbtastic/my-farbtastic.js?ver=3.6.1");
        $document->addScript($urlAssets . "js/codemirror/codemirror.js?ver=3.6.1");

        $document->addScript($urlAssets . "js/codemirror/css.js?ver=3.6.1");

        $document->addScript($urlAssets . "js/codemirror/xml.js?ver=3.6.1");
        $document->addScript($urlAssets . "js/codemirror/overlay.js?ver=3.6.1");
        $document->addScript($urlAssets . "js/showbiz_admin.js?ver=3.6.1");


//add ajax url:
        $currentView = JRequest::getCmd('view', $this->default_view);
        $ajaxUrl = UniteFunctionJoomlaRev::getViewUrl($currentView, "ajax");
        $document->addScriptDeclaration("var g_urlAjax='$ajaxUrl';");

        $this->checkCopyCaptionsCssFile();

        parent::display();

        return $this;
    }
}